<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const obj = { name: "jack", age: "20", gender: "boy" };
      // function objToStr(obj) {
      //   let str = "";
      //   Object.entries(obj).forEach((el) => {
      //     str += `${el[0]}=${el[1]}&`;
      //   });
      //   return str.slice(0, -1);
      // }

      function objToStr(obj) {
        return Object.entries(obj)
          .reduce((str, el) => {
            str += `${el[0]}=${el[1]}&`;
            return str;
          }, "")
          .slice(0, -1);
      }

      console.log(objToStr(obj)); //`name=jack&age=20&gender=boy`;
    </script>
  </body>
</html>
